import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/model/course.dart';
import 'package:kxy_flutter_app/view/course/completed_list_view.dart';
import 'package:line_awesome_icons/line_awesome_icons.dart';

class CourseDetailViewer extends StatelessWidget {
  final Course course;
  const CourseDetailViewer({Key key, @required this.course}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 15),
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20),
      color: Colors.white,
      child: Row(
        children: [
          viewCountText,
          line,
          selectionText,
          Expanded(child: completeBtn(context)),
        ],
      ),
    );
  }

  Text get viewCountText {
    return Text(
      '${course.viewCount}人在学',
      style: TextStyle(
        fontSize: 14,
        color: Colors.black87,
      ),
    );
  }

  Text get selectionText {
    return Text(
      '共${course.resourceList.length}个章节',
      style: TextStyle(
        fontSize: 14,
        color: Colors.black87,
      ),
    );
  }

  Widget get line {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 10),
      child: Text(
        '|',
        style: TextStyle(
          fontSize: 12,
          color: Colors.black38,
        ),
      ),
    );
  }

  Widget completeBtn(BuildContext context) {
    return GestureDetector(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Text(
            '完成情况',
            style: TextStyle(
              fontSize: 14,
              color: Colors.black87,
            ),
          ),
          Icon(LineAwesomeIcons.angle_right, size: 14),
        ],
      ),
      onTap: () {
        Navigator.of(context).push(
          MaterialPageRoute(
            builder: (cxt) => CompletedListView(courseId: course.id),
          ),
        );
      },
    );
  }
}
